<template>
  <div class="customerOverview-container">
    <div class="customerOverview-page">
      <el-card>
        <div>
           <el-button size="small" type="primary" @click="showpop('','add')">新增试料</el-button>
        </div>
        <el-table :data="list" border v-loading="listLoading" style="width: 100%; margin: 20px 0">
          <el-table-column
            label="产品线"
            align="center"
            min-width="100">
            <template slot-scope="scope">
                {{scope.row.goodsLineName}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="试样牌号"
            min-width="150">
            <template slot-scope="scope">
              {{scope.row.goodsSn}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="申请时间"
            min-width="150">
            <template slot-scope="scope">
              {{scope.row.tryTime}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="试样结果"
            min-width="150">
            <template slot-scope="scope">
              {{scope.row.tryResult}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="产品匹配度"
            min-width="150">
            <template slot-scope="scope">
              {{scope.row.tryMatch}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="备注"
            min-width="150">
            <template slot-scope="scope">
              {{scope.row.tryRemark}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="试料凭证报告"
            min-width="150">
            <template slot-scope="scope">
               <img :src="item" v-for="item in scope.row.tryReport" style="width:50px;height:50px;object-fit: contain;cursor: pointer;margin-right:5px;" @click="fullImg(item)"/>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="状态"
            min-width="150">
            <template slot-scope="scope">
              {{scope.row.checkState | fifstate}}
            </template>
          </el-table-column>
          <el-table-column
            fixed="right"
            align="center"
            label="操作"
            min-width="180">
            <template slot-scope="scope">
                <el-button type="text" @click="showSee(scope.row)" size="mini">查看</el-button>
                <el-button type="text" @click="showCl(scope.row)" size="mini" v-if="scope.row.isCanHandle == 1 && scope.row.checkState == 0">填写试用结果</el-button>
                <el-button type="text" size="mini"  v-if="scope.row.isCanHandle == 1 && scope.row.checkState == 0" @click="cancelItem(scope.row)">取消</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="pagination-container">
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            layout="total, sizes,prev, pager, next,jumper"
            :page-size="listQuery.pageSize"
            :page-sizes="[10,15,20]"
            :current-page.sync="listQuery.pageNum"
            :total="count">
          </el-pagination>
        </div>
      </el-card>
    </div>
    <addSl ref="addSl" @getList="getList"></addSl>
    <clSl ref="clSl" @getList="getList"></clSl>
    <seeSl ref="seeSl"></seeSl>
    <!--放大图片-->
    <el-dialog
      :visible.sync="dialogVisible4"
      width="800px">
      <img :src="fullSrc" style="width:100%;"/>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import {formatDate} from '@/utils/date';
import store from '@/store'
import {getCustomerOption, addRelatio, delRelation,} from '@/api/partner'
import {developGoodsTryList,customerNewBaseInfo,developGoodsTryCancel} from '@/api/company'
import addSl from './addSl'
import clSl from './clSl'
import seeSl from './seeSl'
const defaultListQuery={

  customerId:'',
  "pageNum" : 1,
  "pageSize" : 10
};

export default {
  name: "customerSycl",
  data(){
    return{
      roles:store.getters.roles ? store.getters.roles : [],
      list:[],
      listQuery: JSON.parse(JSON.stringify(defaultListQuery)),
      count: 0,
      listLoading: false,
      info:{},
      dialogVisible4:false,
      fullSrc:'',
    }
  },
  components : {
    addSl,clSl,seeSl
  },
  computed: {
    ...mapGetters([
      'name',
      'mobile',
      'userId'
    ]),

  },

  created() {

  },
  filters: {
    fifstate(val){
      if(val == 0){
         return '已申请'
      }else if(val == 10){
         return '已取消'
      }else if(val == 20){
        return '已试样'
      }
    },
  },
  methods:{
    cancelItem(item){
      this.$confirm('确定取消此条记录?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        developGoodsTryCancel({tryId:item.tryId}).then(()=>{
          this.getList();
          this.$message({
            type: 'success',
            message: '已取消!'
          });
        });
      }).catch(() => {

      });
    },
    fullImg(src){
      this.dialogVisible4 = true;
      this.fullSrc = src;
    },
    showSee(item){
      this.$refs.seeSl.showPop(item)
    },
    showCl(item){
      this.$refs.clSl.showPop(item)
    },
    showpop(){
      let data = {
        customerId:this.listQuery.customerId,
        customerName:this.info.customerName
      }
      this.$refs.addSl.showPop(data)
    },
    init(customerId){
      this.listQuery.customerId = customerId;
      this.getList();
      this.getInfo()
    },
    getInfo(){
      customerNewBaseInfo({customerId:this.listQuery.customerId}).then((res)=>{
        this.info = res
      })
    },
    handleSizeChange(val){
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val){
      this.listQuery.pageNum = val;
      this.getList();
    },

    handleSearchList(){
      this.listQuery.pageNum = 1;
      this.getList();
    },
    //获取列表
    getList() {
      this.listLoading = true;
      developGoodsTryList(this.listQuery).then(response => {
        this.list = response.list;
        this.count = response.count;
        this.listLoading = false;
      }).catch(()=>{
        this.listLoading = false;
      });
    },
  }
}
</script>

<style lang="scss">


</style>
